package com.htl.线程;

public class Test4 {
    public static void main(String[] args) {
        Account account = new Account();
        Thread thread1 = new Thread(account,"张三");
        Thread thread2 = new Thread(account,"李四");
        thread1.start();
        thread2.start();
    }
}


class Account implements Runnable{

    private static int num;

    @Override
    public synchronized void run() {
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num++;
        System.out.println(Thread.currentThread().getName() + "是当前的第" + num + "为访客");
    }
}
